package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.domain.CourseDO;

import com.qk.dto.CourseDTO;
import com.qk.entity.Course;
import com.qk.management.service.CourseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/courses")
public class CourseController {
    @Autowired
    private CourseService courseService;


@PutMapping
public Result updateCourse(@RequestBody Course course) {
    log.info("修改课程:{}",course);
    courseService.updateCourse(course);
    return Result.success();
}

    @GetMapping("/{id}")
    public Result getCourseById(@PathVariable Integer id) {
        log.info("查询课程id:{}",id);
        Course course = courseService.getCourseById(id);
        return Result.success(course);
    }


@DeleteMapping("/{id}")
public Result deleteCourse(@PathVariable("id") Integer id) {
    log.info("删除课程id:{}",id);
    courseService.deleteCourse(id);
    return Result.success();
}

    @PostMapping
    public Result addCourse(@RequestBody Course  course){
    log.info("新增课程: {}", course);
        courseService.addCourse(course);
        return Result.success();
    }

    @GetMapping
    public Result getCourses(CourseDTO dto) {
    log.info("查询课程: {}", dto);
        PageResult<CourseDO> userPage = courseService.getCourses(dto);
        return Result.success(userPage);
    }
}
